Given a three-digit positive integer. Find the product of its digits.
Input. One three-digit positive integer n.
Output. Print the product of the digits of n.
Sample
input |
Sample
output |
235 |
30 |
elementary problem
Let n be a
three-digit number. Then:
·
The number of hundreds a is computed as n / 100;
·
The number of tens b is computed as n / 10 % 10;
·
The number of units c is computed as n % 10;
Finally, compute and print
the product a * b * c.
Algorithm implementation
Read
the input data.
scanf("%d",&n);
Compute the hundreds digit a, tens digit b,
and units digit c.
a = n / 100;
b = n / 10 % 10;
c = n % 10;
Compute and print the product of the digits.
res = a * b * c;
printf("%d\n",res);
Java implementation
import java.util.*;
public class Main
{
public static void main(String []args)
{
Scanner con = new Scanner(System.in);
int n = con.nextInt();
int a = n / 100;
int b = n / 10 % 10;
int c = n % 10;
int res = a * b * c;
System.out.println(res);
con.close();
}
}
Python implementation
Read
the input data.
n = int(input())
Compute the hundreds digit a, tens digit b,
and units digit c.
a = n // 100
b = n // 10 % 10
c = n % 10
Compute and print the product of the digits.
res = a * b * c
print(res)
Python implementation – digits
Read
the input data.
n = input()
Compute and print the product of the digits.
res = int(n[0]) * int(n[1]) * int(n[2])
print(res)